package logic

import (
	"cart-go/cartrpc/cartrpc"
	"context"

	"cart-go/api/internal/svc"
	"cart-go/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodAddLogic {
	return &GoodAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodAddLogic) GoodAdd(req *types.GoodAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	goodAdd, err := l.svcCtx.CartRpc.GoodAdd(l.ctx, &cartrpc.GoodAddRequest{
		Name:     req.Name,
		Price:    float32(req.Price),
		Status:   req.Status,
		Stock:    req.Stock,
		Total:    float32(req.Total),
		Quantity: req.Quantity,
		GoodID:   req.GoodID,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "添加成功",
		Code:    200,
		Data:    goodAdd,
	}, nil
}
